package com.zhang.passer.controller;

import com.zhang.passer.domain.ImageDo;
import com.zhang.passer.domain.UserDo;
import com.zhang.passer.domain.YouJiDo;
import com.zhang.passer.service.ImageService;
import com.zhang.passer.service.YoujiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * 页面跳转导航
 */
@Controller
public class IndexController {

    @Autowired
    ImageService imageService;

    @Autowired
    YoujiService youjiService;

    @RequestMapping("/")
    public String index(ModelMap modelMap, HttpSession httpSession){
        //首页图片集合
        List<ImageDo> banner = imageService.queryBanner5();
        List<ImageDo> jingdian = imageService.queryJingdian7();
        List<ImageDo> meishi = imageService.queryMeishi2();
        List<YouJiDo> youji = youjiService.queryNew7();
        modelMap.addAttribute("bannerImage",banner);
        modelMap.addAttribute("jingImage",jingdian);
        modelMap.addAttribute("meishiImage",meishi);
        modelMap.addAttribute("youjis",youji);

        //登录用户信息
        UserDo userInfo=null;
        try{
            userInfo= (UserDo) httpSession.getAttribute("userInfo");
            modelMap.addAttribute("userInfo",userInfo);
        }catch (Exception e){
            // TODO: 2022/1/5 用户未登录记录IP信息到数据库
            System.out.println("未登录");
        }
        return "index";
    }

    @RequestMapping("/jingdian")
    public String toJingdianPage(ModelMap modelMap){
        modelMap.addAttribute("jiudianImage",new ImageDo().setType("jiudian"));
        return "jingdian";
    }


    @RequestMapping("/youji")
    public String toYoujiPage(ModelMap modelMap){
        modelMap.addAttribute("jiudianImage",new ImageDo().setType("jiudian"));
        return "youji";
    }


    @RequestMapping("/meishi")
    public String toMeishiPage(ModelMap modelMap){
        modelMap.addAttribute("jiudianImage",new ImageDo().setType("jiudian"));
        return "meishi";
    }

    /**
     * 根据不同的坐标信息，跳转不同的地图显示
     * @param modelMap
     * @return
     */
    @RequestMapping("/map")
    public String toMapPage(ModelMap modelMap){
        return "map";
    }



    /**
     * 携带查询条件跳转到查询结果页面
     * @param searchValue
     * @param modelMap
     * @return
     */
    @RequestMapping("/searchDetail/{searchValue}")
    public String toSearchDetailPage(@PathVariable String searchValue, ModelMap modelMap){
        modelMap.addAttribute("type","search");
        modelMap.addAttribute("searchValue",searchValue);
        modelMap.addAttribute("jiudianImage",new ImageDo().setType("jiudian"));
        return "detail";
    }


    /**
     * 跳转到不同业务的详情页面
     * @param type
     * @param id
     * @param modelMap
     * @return
     */
    @RequestMapping("/detail/{type}/{id}")
    public String toDetailPage(@PathVariable("type") String type, @PathVariable("id") String id, ModelMap modelMap,HttpSession httpSession){
        //详情页
        modelMap.put("type",type);
        modelMap.put("id",id);
        modelMap.put("jiudianImage",new ImageDo().setType("jiudian"));

        //登录用户信息
        UserDo userInfo=null;
        try{
            userInfo= (UserDo) httpSession.getAttribute("userInfo");
            modelMap.addAttribute("userInfo",userInfo);
        }catch (Exception e){
            // TODO: 2022/1/5 用户未登录记录IP信息到数据库
            System.out.println("未登录");
        }

        return "detail";
    }


}
